package com.itheima.controller;

import com.itheima.domain.dto.ClazzDto;
import com.itheima.domain.pojo.Clazz;
import com.itheima.domain.vo.PageResult;
import com.itheima.domain.vo.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** Clazz-班级管理
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-08-19 10:06
 */
@RestController
@Slf4j
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    /** 获取班级列表 */
    @GetMapping
    public Result getClazzList(ClazzDto clazzDto){
        PageResult pageResult = clazzService.getClazzList(clazzDto);
        return Result.success(pageResult);
    }

    /** 删除班级 */
    @DeleteMapping("/{id}")
    public Result deleteClazz(@PathVariable Integer id){
        clazzService.deleteClazz(id);
        return Result.success();
    }

    /** 添加班级 */
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){
        clazzService.addClazz(clazz);
        return Result.success();
    }

    /** 根据id查询班级 */
    @GetMapping("/{id}")
    public Result getClazzId(@PathVariable("id") Integer id){
        Clazz clazz = clazzService.getClazzId(id);
        return Result.success(clazz);
    }

    /** 修改班级 */
    @PutMapping
    public Result updateClazz(@RequestBody Clazz clazz){
        clazzService.updateClazz(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getClazzList(Clazz clazz){
        List<Clazz> clazzList = clazzService.selectClazzList(clazz);
        return Result.success(clazzList);
    }
}
